package service;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Utils {
	public static Map<Integer, String> listToMap(List<CommonType> list){
		Map<Integer, String> map = new HashMap<Integer, String>();
		
		for (CommonType item : list) map.put(item.id, item.name);
		
		return map;
	}
	
	/*
	 * Example: Date date = Utils.stringToDate("2014/01/25");
	 */
	public static Date stringToDate(String dateString){
    	DateFormat df = new SimpleDateFormat(Constant.dateFormat);
    	Date result = null;
    	
    	try {
    		if(dateString != null)
    			result =  df.parse(dateString);
		} catch (ParseException e) {

		}  
    	
    	return result;
	}
	
	public static int parseToDateKey(String dateString){
    	int result = 0;
		
    	try {
    		if(dateString != null)
    			result = Integer.parseInt(dateString.replace("/", ""));
		} catch (Exception e) {
		}  
    	
    	return result;
	}
}
